<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/vue@next"></script>
</head>

<body>
    <div id="app">
        <input type="text" v-model="ipt" @keyup.enter="add()">
        <div v-for="ele in filterToDo">
            <span>
                <input type="checkbox" v-model="ele.checked">
            </span>
            {{ele.item}}
        </div>
        <button @click="showHandle('all')">显示全部</button>
        <button @click="showHandle('unDone')">显示未选中</button>
        <button @click="showHandle('done')">显示选中</button>
    </div>
</body>
<script>
    const filter = {
        all: (arr) => arr,
        unDone: (arr) => arr.filter(ele => ele.checked == false),
        done: (arr) => arr.filter(ele => ele.checked == true),
    }

    let vm = {
        data () {
            return {
                type: 'all',
                ipt: '',
                arr: [
                    { item: '吃饭', checked: false },
                    { item: '喝水', checked: false },
                    { item: '睡觉', checked: false },
                ]
            }
        },
        methods: {
            add () {
                if (this.ipt) {
                    this.arr.unshift({ item: this.ipt, checked: false })
                    this.ipt = ''
                }
            },
            showHandle (data) {
                this.type = data
            }
        },
        computed: {
            filterToDo () {
                return filter[this.type](this.arr)
            },
        },
    }
    Vue.createApp(vm).mount('#app')
</script>

</html>